package com.teichmann;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;

import com.teichmann.core.targets.online.revolution.BasicPage;
import com.teichmann.core.targets.online.revolution.OnlineExecutor;


@SuppressWarnings("serial")
public class BuscaCarrosServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

		execute(req, resp);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {

		execute(req, resp);
		
	}

	private void execute(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		if (!StringUtils.isEmpty(req.getParameter("modelo")) ) {
			OnlineExecutor oe = new OnlineExecutor(req.getParameter("modelo"));
			List<BasicPage> pages = oe.execute();

			req.getSession().removeAttribute("cars");
			req.getSession().setAttribute("pages", pages);
			req.getSession().setMaxInactiveInterval(50);
		}
	}

}
